import { get } from "./ajax";

const baseUrl = "/api/question/published";

export default async function getQuestionById(
  questionId: string,
  isPrompt?: boolean,
  answerId?: string
) {
  try {
    return await get(
      `${baseUrl}/${questionId}${answerId ? "?answerId=" + answerId : ""}${
        isPrompt ? "&isPrompt=" + isPrompt : ""
      }`
    );
  } catch (error) {
    console.error("Error fetching question:", error);
    // 返回一个标准的错误格式，与服务端错误格式保持一致
    return {
      code: 1,
      message: error instanceof Error ? error.message : "获取问卷失败",
      result: null,
    };
  }
}
